package hypeerweb;

import hypeerweb.Node;

public abstract class Command
{
    
    public void execute(Node opNode, Node startNode)
    {
        Node extreme = findExtremePoint(startNode);
        Node opPoint = findOpPoint(extreme);
        connect(opNode, opPoint);
    }
    
    public Node findExtremePoint(Node currNode)
    {
        if(isExtreme(currNode))
        {
            return currNode;
        }
        return findExtremePoint(goExtreme(currNode));
    }
    
    public Node findOpPoint(Node currNode)
    {
        if(isOpPoint(currNode))
        {
            return currNode;
        }
        return findOpPoint(goOpPoint(currNode));
    }
    
    public abstract boolean isExtreme(Node currNode);
    public abstract Node    goExtreme(Node currNode);
    public abstract boolean isOpPoint(Node currNode);
    public abstract Node    goOpPoint(Node currNode);
    public abstract void    connect(Node opNode, Node opPoint);
}
